﻿/****************************************************************************
** file: cvQDebug.h
** brief: 使用 QDebug 输出 OpenCV 的各种数据结果。用于调试代码时使用。
** Copyright (C) LiYuan
** Author: LiYuan
** E-Mail: 18069211#qq(.)com
** Version 1.0.0
** Last modified: 2024.4.3
** Modified By: LiYuan
****************************************************************************/


#ifndef CVQDEBUG_H
#define CVQDEBUG_H

#include <QDebug>
#include <opencv2/core.hpp>

inline QDebug operator<<(QDebug dbg, const cv::Size &size)
{
    dbg << "Size( width = " << size.width << ", height = " << size.height << ")";
    return dbg;
}

inline QDebug operator<<(QDebug dbg, const cv::Size2f &size)
{
    dbg << "Size2f( width = " << size.width << ", height = " << size.height << ")";
    return dbg;
}

inline QDebug operator<<(QDebug dbg, const cv::Size2d &size)
{
    dbg << "Size2d( width = " << size.width << ", height = " << size.height << ")";
    return dbg;
}

inline QDebug operator<<(QDebug dbg, const cv::Size2l &size)
{
    dbg << "Size2l( width = " << size.width << ", height = " << size.height << ")";
    return dbg;
}

inline QDebug operator<<(QDebug dbg, const cv::Point2f &p)
{
    dbg << "Point2f(" << p.x << ", " << p.y << ")";
    return dbg;
}

inline QDebug operator<<(QDebug dbg, const cv::Point2i &p)
{
    dbg << "Point2i(" << p.x << ", " << p.y << ")";
    return dbg;
}

inline QDebug operator<<(QDebug dbg, const cv::Point2d &p)
{
    dbg << "Point2d(" << p.x << ", " << p.y << ")";
    return dbg;
}

inline QDebug operator<<(QDebug dbg, const cv::Rect &rect)
{
    dbg << "Rect( (x, y) = (" << rect.x << "," << rect.y << "), width = " << rect.width << ", height = " << rect.height << ")";
    return dbg;
}

inline QDebug operator<<(QDebug dbg, const cv::RotatedRect &rrt)
{
    dbg << "RotatedRect(center = " << rrt.center << ", Size = " << rrt.size << ", angle = " << rrt.angle << ")";
    return dbg;
}

inline QDebug operator<<(QDebug dbg, const cv::Mat &mat)
{
    QString depth;
    switch(mat.depth())
    {
        case CV_8U: depth = "CV_8U"; break;
        case CV_8S: depth = "CV_8S"; break;
        case CV_16U: depth = "CV_16U"; break;
        case CV_16S: depth = "CV_16S"; break;
        case CV_16F: depth = "CV_16F"; break;
        case CV_32S: depth = "CV_32S"; break;
        case CV_32F: depth = "CV_32F"; break;
    }
    dbg << "Mat(" << mat.size() << ", depth = " << depth  << ", channel = " << mat.channels() << ")";
    return dbg;
}


#endif // CVQDEBUG_H
